using UniversalAdmin.Domain.Repositories;
using UniversalAdmin.Infrastructure.Data.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using UniversalAdmin.Infrastructure.Repositories;

namespace UniversalAdmin.Infrastructure
{
  /// <summary>
  /// 服务集合扩展类
  /// </summary>
  public static class ServiceCollectionExtenstion
  {
    /// <summary>
    /// 添加基础设施层服务
    /// </summary>
    /// <param name="services"></param>
    /// <param name="configuration"></param>
    /// <returns></returns>
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {
      var conString = configuration.GetConnectionString("pgsql");
      services.AddDbContext<AdminDbContext>(item =>
      {
        item.UseNpgsql(conString);
      });
      services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
      return services;
    }
  }
}

